package com.kotlin.day02

import org.junit.Test

class Test01AnonymousFun {
    @Test
    fun test01() {
        val total = "mississippi".count();
        val totalS = "mississippi".count({ letter -> letter == 's' })
        println(total)//11
        println(totalS)//4

        //变量的类型是一个匿名函数
        val end: () -> String = {
            val holiday = "New Year"
            "Happy $holiday"
        }
        println(end())  //Happy New Year


    }

    @Test
    fun test02() {
        val blessingFunction: (String) -> String = { name ->
            val age = 18
            "名字为：$name，年龄为：$age，欢迎你！"

        }
        println(blessingFunction("jack"))   //名字为：jack，年龄为：18，欢迎你！

        val blessingFunction2: (String) -> String = {
            val age = 18
            "名字为：$it，年龄为：$age，欢迎你！"
        }
        println(blessingFunction2("jack"))   //名字为：jack，年龄为：18，欢迎你！
    }
    @Test
    fun test03() {
        //类型推断
        val fun1 = {name:String,year:Int->
            val holiday = "New Year"
            "$name , Happy $holiday,$year"
        }
        //jack , Happy New Year,2027
        println(fun1("jack",2027)) ;
    }

}